//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    charDictList: [],
    // imgUrls: [
    //   "https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=2512412073,484693686&fm=27&gp=0.jpg",
    //   "https://ss0.bdstatic.com/70cFvHSh_Q1YnxGkpoWK1HF6hhy/it/u=231620273,2622968107&fm=27&gp=0.jpg",
    //   "https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=281531042,273318123&fm=27&gp=0.jpg",
    //   "http://img4.imgtn.bdimg.com/it/u=2731345960,2613387946&fm=26&gp=0.jpg"
    // ],
    currentIndex:0
  },

  onShow(){
    // const that = this;
    // const app = getApp();
    // const openid = this.data.openid;
    // console.log(this.data, '83-83 userForm.js:::::onShow:::this.data:');
    // if(!openid) return;
    // app.globalData.userDoc.doc(openid).get({
    //     success(res){
    //         console.log('77-77 userForm.js:::::onShow:::success::res:', res);
    //         // const userInfoJson = JSON.stringify(res.data.user);
    //         const user = res.data.user;
    //         const someUserInfoDict = {
    //           stageindex: user.stageindex,
    //           slogan: user.slogan,
    //         }
    //         that.setData({
    //           _id: openid,
    //           user: someUserInfoDict,
    //         });
    //     },
    //     fail: console.error,
    // });
  },
  onLoad: function (options) {
    const that = this;
    const {stageindex} = options;
    this.setData({
      stageindex,
    });
    if(stageindex){
      const app = getApp();
      console.log('41-41 app.globalData.charDoc: ', app.globalData.charDoc);
      // wx.cloud.database().collection('yiling_collection_char')
      app.globalData.charDoc
      .where({
        stageindex: stageindex,
      })
      .get().then(res=>{
      console.log('77-77 coursePage.js:::::onShow:::success::res:', res);
            // const userInfoJson = JSON.stringify(res.data.user);
            const charDictList = res.data.map(charDict=>{
              return {
                char: charDict.char,
                pinyin: charDict.pinyin,
                stageindex: charDict.stageindex,
                voice: charDict.voice,
              };
            });
            that.setData({
              charDictList,
            });
    }).catch(err=>{
      console.error(err);
    });
    }
  },
  
  swiperChange(e){
    console.log(e)
    this.setData({
      currentIndex:e.detail.current
    })
  },
  
  toLinkPage(e){
    wx.navigateTo({
      url: e.currentTarget.dataset.link,
    });
  },

})
